package com.aegean.MonitorExamSYS.center.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.center.business.CenterBusiness;
import com.aegean.MonitorExamSYS.center.component.SelectPosition;
import com.opensymphony.xwork2.ActionSupport;

@Controller("ShowPositionListForMonitor")
@Scope("prototype")
public class ShowPositionListForMonitor extends ActionSupport implements ServletRequestAware{
	@Resource
	CenterBusiness business;
	private HttpSession session;
	private HttpServletRequest request;
	private List<SelectPosition> positions;
	private int total;
	private int exam_Id;

	public List<SelectPosition> getPositions() {
		return positions;
	}

	public void setPositions(List<SelectPosition> positions) {
		this.positions = positions;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getExam_Id() {
		return exam_Id;
	}

	public void setExam_Id(int exam_Id) {
		this.exam_Id = exam_Id;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		try {
			positions = business.showPositionListForMonitor(exam_Id);
			if (positions.isEmpty() == true) {
				total = 0;
			} else {
				total = positions.size();
			}
			session.setAttribute("SelectPositionForMontior",positions);//该考试对应的所有考场资格信息存储Session
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return SUCCESS;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request=arg0;
		this.session=request.getSession();
	}
}
